package com.hhh.springai_test.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hhh.springai_test.common.BaseResponse;
import com.hhh.springai_test.common.ResultUtils;
import com.hhh.springai_test.constant.UserConstant;
import com.hhh.springai_test.model.dto.commentreply.AddCommentReplyDTO;
import com.hhh.springai_test.model.dto.commentreply.QueryCommentReplyDTO;
import com.hhh.springai_test.model.dto.commentreply.UpdateCommentReplyDTO;
import com.hhh.springai_test.model.po.CommentReply;
import com.hhh.springai_test.model.vo.CommentReplyVO;
import com.hhh.springai_test.service.CommentReplyService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/commentReply")
public class CommentReplyController {

    @Resource
    private CommentReplyService commentReplyService;

    @PostMapping("/add")
    @SaCheckRole(UserConstant.DEFAULT_ROLE)
    public BaseResponse<Long> addCommentReply(@RequestBody AddCommentReplyDTO addCommentReplyDTO) {
        String loginId = (String) StpUtil.getLoginId();
        Long userId = Long.valueOf(loginId);
        Long replyId = commentReplyService.addCommentReply(addCommentReplyDTO, userId);
        return ResultUtils.success(replyId);
    }

    @PostMapping("/delete/{id}")
    @SaCheckRole(UserConstant.DEFAULT_ROLE)
    public BaseResponse<Boolean> deleteCommentReply(@PathVariable Long id) {
        String loginId = (String) StpUtil.getLoginId();
        Long userId = Long.valueOf(loginId);
        boolean result = commentReplyService.deleteCommentReply(id, userId);
        return ResultUtils.success(result);
    }

    @PostMapping("/update")
    @SaCheckRole(UserConstant.DEFAULT_ROLE)
    public BaseResponse<Boolean> updateCommentReply(@RequestBody UpdateCommentReplyDTO updateCommentReplyDTO) {
        String loginId = (String) StpUtil.getLoginId();
        Long userId = Long.valueOf(loginId);
        boolean result = commentReplyService.updateCommentReply(updateCommentReplyDTO, userId);
        return ResultUtils.success(result);
    }

    @PostMapping("/list")
    public BaseResponse<Page<CommentReplyVO>> listCommentReplyPage(@RequestBody QueryCommentReplyDTO queryCommentReplyDTO) {
        Page<CommentReplyVO> replyPage = commentReplyService.queryCommentReplyPage(queryCommentReplyDTO);
        return ResultUtils.success(replyPage);
    }
}
